package com.example.springbootrabbitmq.consumer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @author 墨苍璃
 * @date 2022年09月20日00时32分
 * <p>
 * 报警消费者
 */
@Component
@Slf4j
public class WarningConsumer {

    public static final String WARNING_QUEUE_NAME = "warning.queue";
    public static final String BACKUP_QUEUE_NAME = "backup.queue";

    /**
     * 监听  warning.queue
     *
     * @param message
     */
    @RabbitListener(queues = WARNING_QUEUE_NAME)
    public void receiveWarningMsg(Message message) {
        String msg = new String(message.getBody());
        log.error("报警发现不可路由消息：  {}", msg);
    }


    /**
     * 监听  backup.queue
     *
     * @param message
     */
    @RabbitListener(queues = BACKUP_QUEUE_NAME)
    public void receiveBackupMsg(Message message) {
        String msg = new String(message.getBody());
        log.error("备份交换机处理消息：  {}", msg);
    }

}